<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        button {
            position: absolute;
            left: 0;
        }
    </style>
</head>

<body>
    <button>移动按钮</button>
    <script>
        // 函数没执行一次就会产生一个内存空间

        //闭包：子函数能访问到其他函数中的变量
        let arr = [1, 23, 3, 4, 56, 5, 7, 8, 9, 12, 18];
        // 闭包获取区间的值
        function between(a, b) { // a - b 区间
            return function (v) { // v 数组中的值
                return v >= a && v <= b;
            }
        }
        console.log(arr.filter(between(3, 9)))
        let timer = null;
        let left = 0;
        
        document.querySelector('button').addEventListener('click', function () {
            clearInterval(timer);
            timer = setInterval(() => {
                this.style.left = left++ + 'px'
            }, 100);
        })
    </script>
</body>

</html>